import moduleCreator from '../moduleCreator'

import api from '@/api'

const modelName = 'res.partner'

const fields = {
  name: null
  // list_price: null,
  // standard_price: null
}

const config = {
  model: modelName,
  fieldsForSearch: fields,
  fieldsForBrowse: fields
}

const state = {
  //
}

const mutations = {
  //
}

const actions = {
  async search({ commit, state, dispatch }, payload) {
    return dispatch('_search', payload)
  },
  async browse_one({ commit, state, dispatch }, payload) {
    return dispatch('_browse_one', payload)
  },

  async channel_get({ commit, state, dispatch }, { id }) {
    const cnl = await api.env('mail.channel').channel_get([id])
    commit('UPDATE_DataDict', { private_channel_id: cnl.id })
    console.log('channel_get ', cnl)
    // return state.dataDict
    return new Promise(resolve => {
      resolve(cnl)
    })
  }
}

export default moduleCreator(config, {
  namespaced: true,
  state,
  mutations,
  actions
})
